﻿using System;
using System.Windows.Forms;
using System.Drawing.Design;
using System.ComponentModel;
using System.Windows.Forms.Design;
using SedionFormDesigner.CustControls.ComboBox;

namespace SedionFormDesigner.CusControls.TypeEditor
{
    public class DataSourceEditor : UITypeEditor
    {
        public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
        {
            return UITypeEditorEditStyle.Modal;
        }

        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            IWindowsFormsEditorService editorService = null;

            if (context != null && context.Instance != null)
            {
                editorService = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
                if (editorService != null)
                {
                    String sql = value == null ? null : value.ToString();
                    FrmSQL frmSQL = FrmSQL.CreateFrmInstace(sql);
                    if (frmSQL.ShowDialog() == DialogResult.OK)
                    {
                        value = frmSQL.GetSQL();
                    }
                    return value;
                }
            }
            return base.EditValue(context, provider, value);
        }

    }
}
